﻿/*
 * QWine Queue Machine (Special build for Immigration Office)
 * Copyright (C) 2010 Wish Enterprise Development Team

 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 * 
 * Contact Us:
 * E-Mail   : contact@wishenterprise.com
 * 
 * */

using System;
using System.Runtime.InteropServices;

namespace QWRepository
{
    /// <summary>
    /// WavPlayer
    /// </summary>
    public class WavPlayer
    {
        #region PlaySoundFlags enum

        [Flags]
        public enum PlaySoundFlags
        {
// ReSharper disable InconsistentNaming
            SND_SYNC = 0x0000,
// ReSharper restore InconsistentNaming
// ReSharper disable InconsistentNaming
            SND_ASYNC = 0x0001,
// ReSharper restore InconsistentNaming
// ReSharper disable InconsistentNaming
            SND_NODEFAULT = 0x0002,
// ReSharper restore InconsistentNaming
// ReSharper disable InconsistentNaming
            SND_LOOP = 0x0008,
// ReSharper restore InconsistentNaming
// ReSharper disable InconsistentNaming
            SND_NOSTOP = 0x0010,
// ReSharper restore InconsistentNaming
// ReSharper disable InconsistentNaming
            SND_NOWAIT = 0x00002000,
// ReSharper restore InconsistentNaming
// ReSharper disable InconsistentNaming
            SND_FILENAME = 0x00020000,
// ReSharper restore InconsistentNaming
// ReSharper disable InconsistentNaming
            SND_RESOURCE = 0x00040004
// ReSharper restore InconsistentNaming
        }

        #endregion

        /// <summary>
        /// Plays the sound.
        /// </summary>
        /// <param name="szSound">The sz sound.</param>
        /// <param name="hMod">The h mod.</param>
        /// <param name="flags">The flags.</param>
        /// <returns></returns>
        [DllImport("WinMM.dll", EntryPoint = "PlaySound", SetLastError = true)]
        private static extern bool PlaySound(string szSound, IntPtr hMod, PlaySoundFlags flags);

        /// <summary>
        /// Plays the sound.
        /// </summary>
        /// <param name="param">The param.</param>
        public static void PlaySound(string param)
        {
            PlaySound(string.Format("./Sound/{0}.wav", param), (IntPtr) 44100, PlaySoundFlags.SND_FILENAME);
        }

        public static void PlaySoundByPath(string path)
        {
            PlaySound(string.Format(path), (IntPtr) 44100, PlaySoundFlags.SND_FILENAME);
        }
    }
}